//
//  UISearchBarDemo.swift
//  firstProject
//
//  Created by 张彦辉 on 2017/3/27.
//  Copyright © 2017年 张彦辉. All rights reserved.
//

import UIKit
import SnapKit

class UISearchBarDemo: UIViewController ,UISearchBarDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.gray
        let searchBar = UISearchBar()
        //设置搜索框上的默认提示文字
        searchBar.placeholder = "请输入关键字"
        //设置搜索框上显示的默认文字
        searchBar.text = "剑圣"
        //设置摸索框样式
        searchBar.barStyle = .default
        //设置搜索框背景文字
        searchBar.prompt = "背景文字"
        //设置功能按钮的显示
//        searchBar.showsBookmarkButton = true
//        searchBar.showsCancelButton = true
//        searchBar.showsSearchResultsButton = true
        
        //设置渲染颜色
        searchBar.tintColor = UIColor.red
        //设置搜索框的颜色
        searchBar.barTintColor = UIColor.green
        //设置附件视图
        searchBar.scopeButtonTitles=["1","2","3"]
        searchBar.showsScopeBar = true
        searchBar.delegate = self
        self.view.addSubview(searchBar)
        searchBar.snp.makeConstraints { (maker) in
            maker.width.equalTo(self.view)
            maker.top.equalTo(80)
        }
        

    }
    //
    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        print("文本改变：\(searchText)")
        
    }
    func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
        print("按钮切换：\(selectedScope)")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
